<template>
  <div class="login-container">
    <div class="form-box">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="pass">
          <el-input
            type="text"
            v-model="ruleForm.username"
            autocomplete="off"
            prefix-icon="el-icon-user-solid"
          ></el-input>
        </el-form-item>
        <el-form-item prop="checkPass">
          <el-input
            type="password"
            v-model="ruleForm.password"
            prefix-icon="el-icon-s-opportunity"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item class="btn">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >提交</el-button
          >
          <el-button style="background: #95989d" @click="resetForm('ruleForm')"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <div class="img"><img src="../../assets/logo.png" alt="" /></div>
      <div class="box1">32</div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      ruleForm: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          console.log(1)
          await this.$store.dispatch('user/login', this.ruleForm)
          this.$message.success('登录成功')
          this.$router.push('/')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang='less'  scoped>
.login-container {
  background-color: #2b4b6b;
  width: 100vw;
  height: 100vh;
  position: relative;
  .form-box {
    position: relative;
    box-shadow: 20px 20px -5px -5px rgba(114, 124, 245, 1);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding-top: 50px;
    width: 450px;
    height: 300px;
    background-color: #fff;
    .el-form {
      margin: 60px 40px;
      button {
        font-size: 14px;
        color: white;
        &.submit {
          background-color: #727cf5;
        }
        padding: 10px 20px;
      }
    }
    .btn {
      float: right;
    }
  }
}
.box1 {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background-color: #fff;
  position: absolute;
  overflow: hidden;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px #ddd;
  top: -23%;
}
.img {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background-color: #eeeeee;
  position: absolute;
  overflow: hidden;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  top: -20%;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
